package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Keyon
 * @Date 2019/11/9 16:08
 * @Desc
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password) {
        return userService.login(username, password);
    }

    @RequestMapping("find")
    public String findAllUser() {
        return userService.getAllUser().toString();
    }

    @RequestMapping("findById/{id}")
    public User findUserById(@PathVariable("id") long id) {
        return userService.getUserById(id);
    }

    @RequestMapping("update")
    public void updateUserById(@RequestParam("id") long id,
                               @RequestParam("userName") String userName) {
        userService.updateUserById(id, userName);
    }

}
